home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.09 Sep 93 / FrameAnim App ƒ / Dialogs.c < prev    next >
Encoding:
Text File  |  1994-11-06  |  7.5 KB  |  273 lines  |  [TEXT/KAHL]

  1. // ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  2. // • Program:    FrameAnim
  3. // • File:        Dialogs.c
  4. // •
  5. // • Copyright © 1993 by Scott B. Steinman, O.D., Ph.D. All Rights Reserved.
  6. // ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  7.  
  8. #include "FrameAnim.h"
  9.  
  10. // • ------------------ External Globals ---------------------------------- 
  11.  
  12. extern CWindowPtr        gMainWindow;    // • From Main.c file    
  13. extern Settings            gSettings;        // • From Main.c file
  14. extern Flags            gFlags;         // • From Main.c file
  15.  
  16. // • ------------------ Film Control Dialog Box --------------------------- 
  17.  
  18. void
  19. FilmDlg( void )
  20. // •
  21. // • Dialog box that appears before filming.
  22. {
  23.     DialogRecord        dStorage;
  24.     DialogPtr            theDialog = NullPointer;
  25.     Handle                numFramesItem = NullHandle, 
  26.                         frameDelayItem = NullHandle, 
  27.                         sizeDiffItem = NullHandle;
  28.     Rect                box;
  29.     long                frames, delay, sizeDiff;
  30.     short                itemHit, kind;
  31.     Boolean                notProper = false;
  32.     Str255                numFramesText, frameDelayText, sizeDiffText;
  33.         
  34.     gFlags.cancel = false;      
  35.     frames = gSettings.numFrames;
  36.     delay = gSettings.frameDelay;
  37.     sizeDiff = gSettings.sizeDiff;        
  38.     NumToString( frames, &numFramesText );
  39.     NumToString( delay, &frameDelayText );
  40.     NumToString( sizeDiff, &sizeDiffText );
  41.     
  42.     theDialog = GetNewDialog( kFilmDlgID, &dStorage, (WindowPtr) kMoveToFront );    
  43.     
  44.     GetDItem( theDialog, kFilmDlgNumFrames, &kind, &numFramesItem, &box );
  45.     SetIText( numFramesItem, &numFramesText );    
  46.     GetDItem( theDialog, kFilmDlgFrameDelay, &kind, &frameDelayItem, &box );
  47.     SetIText( frameDelayItem, &frameDelayText );    
  48.     GetDItem( theDialog, kFilmDlgSizeDiff, &kind, &sizeDiffItem, &box );
  49.     SetIText( sizeDiffItem, &sizeDiffText );    
  50.     
  51.     do {
  52.         ModalDialog( NullPointer, &itemHit );        
  53.         GetIText( numFramesItem, &numFramesText );
  54.         GetIText( frameDelayItem, &frameDelayText );
  55.         GetIText( sizeDiffItem, &sizeDiffText );    
  56.     } while ( itemHit != kFilmDlgGoAhead && itemHit != kFilmDlgCancel );
  57.  
  58.     CloseDialog( theDialog );
  59.  
  60.     if (itemHit == kFilmDlgCancel)                 
  61.         gFlags.cancel = true;              
  62.     else {                                        
  63.         StringToNum( &numFramesText, &frames );
  64.         StringToNum( &frameDelayText, &delay );
  65.         StringToNum( &sizeDiffText, &sizeDiff );
  66.         
  67.         // • Make sure all values are within their proper ranges!         
  68.         
  69.         if (sizeDiff <= 0 || sizeDiff > kMaxSizeDiff)            
  70.             notProper = true;
  71.         if (frames <= 0 || frames > kMaxFrames)            
  72.             notProper = true;
  73.         if (delay < 1) 
  74.             notProper = true;
  75.         
  76.         if (notProper == true) {            // • Call Dialog again if not proper 
  77.             SysBeep( 1 );
  78.             FilmDlg();
  79.         }
  80.         else {
  81.             gSettings.numFrames = frames;
  82.             gSettings.frameDelay = delay;
  83.             gSettings.sizeDiff = sizeDiff;        
  84.         
  85.             EnableItem( GetMHandle( kAnimID ), kPlayItem );
  86.         }
  87.     }
  88. }
  89.  
  90. // • ------------------ Frame Size Dialog Box ----------------------------- 
  91.  
  92. void
  93. FrameSzDlg( void )
  94. // •
  95. // • Dialog box that is called when frame dimensions are to be changed.
  96. {
  97.     DialogRecord        dStorage;
  98.     DialogPtr            theDialog = NullPointer;
  99.     Handle                diamItem = NullHandle;
  100.     Rect                box;
  101.     long                diam;
  102.     short                itemHit, kind;
  103.     Boolean                notProper = false;
  104.     Str255                diamText;
  105.     
  106.     gFlags.cancel = false;    
  107.     diam = gSettings.frameSize;                        
  108.     NumToString( diam, &diamText );
  109.  
  110.     theDialog = GetNewDialog( kFrameSzDlgID, &dStorage, (WindowPtr) kMoveToFront );        
  111.  
  112.     GetDItem( theDialog, kFrameSzDlgDiam, &kind, &diamItem, &box );
  113.     SetIText( diamItem, &diamText );
  114.  
  115.     do {
  116.         ModalDialog( NullPointer, &itemHit );        
  117.         GetIText( diamItem, &diamText );
  118.     } while (itemHit != kFrameSzDlgGoAhead && itemHit != kFrameSzDlgCancel);
  119.     
  120.     CloseDialog( theDialog );
  121.     
  122.     if (itemHit == kFrameSzDlgCancel)            
  123.         gFlags.cancel = true;              
  124.     else {                                        
  125.         StringToNum( &diamText, &diam );
  126.         
  127.         if (diam < 20) {
  128.             SysBeep( 1 );
  129.             FrameSzDlg();
  130.         }
  131.         else {
  132.             gSettings.frameSize = diam;
  133.         
  134.             // • Force user to rebuild GWorlds
  135.             DisableItem( GetMHandle( kAnimID ), kPlayItem );
  136.         }
  137.     }    
  138. }
  139.  
  140. // • ------------------ Gray Scale Dialog Box ----------------------------- 
  141.  
  142. void
  143. GrayDlg( void )
  144. // •
  145. // • This is the dialog box that is called when you want the gray scale info.
  146. // • The user may choose the gray value of the background or target.
  147. {
  148.     DialogRecord        dStorage;
  149.     DialogPtr            theDialog = NullPointer;
  150.     Handle                targetGrayItem = NullHandle, 
  151.                         bkgndGrayItem = NullHandle;
  152.     Rect                box;
  153.     long                tGray, bGray; 
  154.     short                itemHit, kind, i;
  155.     Boolean                notProper = false;
  156.     Str255                targetGrayText, bkgndGrayText;
  157.  
  158.     gFlags.cancel = false;                        
  159.     bGray = gSettings.bkgndGray;
  160.     tGray = gSettings.targetGray;
  161.     NumToString( bGray, &bkgndGrayText );
  162.     NumToString( tGray, &targetGrayText );
  163.     
  164.     theDialog = GetNewDialog( kGrayDlgID, &dStorage, (WindowPtr) kMoveToFront );    
  165.  
  166.     GetDItem( theDialog, kGrayDlgBkgndGray, &kind, &bkgndGrayItem, &box );
  167.     SetIText( bkgndGrayItem, &bkgndGrayText );    
  168.     GetDItem( theDialog, kGrayDlgTargetGray, &kind, &targetGrayItem, &box );
  169.     SetIText( targetGrayItem, &targetGrayText );    
  170.         
  171.     do {
  172.         ModalDialog( NullPointer, &itemHit );
  173.         GetIText( bkgndGrayItem, &bkgndGrayText );
  174.         GetIText( targetGrayItem, &targetGrayText );
  175.         
  176.     } while ( itemHit != kGrayDlgGoAhead && itemHit != kGrayDlgCancel );
  177.  
  178.     CloseDialog( theDialog );
  179.  
  180.     if (itemHit == kGrayDlgCancel)            
  181.         gFlags.cancel = true;              
  182.     else {                                        
  183.         StringToNum( &bkgndGrayText, &bGray );
  184.         StringToNum( &targetGrayText, &tGray );
  185.         
  186.         // • Make sure all values are within their proper ranges!         
  187.  
  188.         if (bGray < 0 || bGray > 255)     
  189.             notProper = true;
  190.         if (tGray < 0 || tGray > 255)     
  191.             notProper = true;
  192.  
  193.         if (notProper == true) {                // • Call Dialog again if not proper 
  194.             SysBeep( 1 );
  195.             GrayDlg();
  196.         }
  197.         else {
  198.             // • Force user to rebuild GWorlds
  199.             DisableItem( GetMHandle( kAnimID ), kPlayItem );
  200.             
  201.             gSettings.bkgndGray = bGray;
  202.             gSettings.targetGray = tGray;
  203.             
  204.             UpdateWindowColors();                // • Reset palettes if colors changed 
  205.             PmBackColor( kPalBkgnd );
  206.             EraseRect( &gMainWindow->portRect );    // • Clear the area completely 
  207.         }
  208.     }
  209. }
  210.  
  211. // • ------------------ Set Display Monitor Dialog Box -------------------- 
  212.  
  213. void
  214. MonitorDlg( void )
  215. // •
  216. // • Dialog box that is called to set choice of display monitor.
  217. {
  218.     DialogRecord        dStorage;
  219.     DialogPtr            theDialog = NullPointer;
  220.     Handle                theHandle = NullHandle;
  221.     ControlHandle        mainMonRadio = NullHandle, 
  222.                         secMonRadio = NullHandle;
  223.     Rect                box;
  224.     short                mainMon = 0, secMon = 0, thePart, itemHit, kind, index;
  225.     Boolean                notProper = false;
  226.  
  227.     gFlags.cancel = false;                            
  228.     switch (gSettings.displayMonitor) {
  229.         case kMain:                mainMon = 1;    break;
  230.         case kSecondary:        secMon = 1;        break;
  231.     }
  232.     
  233.     theDialog = GetNewDialog( kMonitorDlgID, &dStorage, (WindowPtr) kMoveToFront );    
  234.     
  235.     GetDItem( theDialog, kMonitorDlgMainMon, &kind, &theHandle, &box );    
  236.     mainMonRadio = (ControlHandle) theHandle;        
  237.     SetCtlValue( mainMonRadio, mainMon );
  238.     GetDItem( theDialog, kMonitorDlgSecMon, &kind, &theHandle, &box );    
  239.     secMonRadio = (ControlHandle) theHandle;        
  240.     SetCtlValue( secMonRadio, secMon );
  241.  
  242.     do {
  243.         ModalDialog( NullPointer, &itemHit );
  244.         
  245.         // • Make the radio buttons switch around. 
  246.         
  247.         switch (itemHit) {
  248.             case kMonitorDlgMainMon:
  249.                 mainMon = 1;
  250.                 secMon = 0;
  251.                 break;
  252.             case kMonitorDlgSecMon:
  253.                 secMon = 1;
  254.                 mainMon = 0;
  255.                 break;
  256.         }
  257.         SetCtlValue( mainMonRadio, mainMon );
  258.         SetCtlValue( secMonRadio, secMon );
  259.     } while ( itemHit != kMonitorDlgGoAhead && itemHit != kMonitorDlgCancel );
  260.  
  261.     CloseDialog( theDialog );
  262.  
  263.     if (itemHit == kMonitorDlgCancel) {            
  264.         gFlags.cancel = true;   
  265.         gSettings.displayMonitor = kMain;
  266.     }           
  267.     else {                                        
  268.         if (mainMon == 1)            gSettings.displayMonitor = kMain;
  269.         else if (secMon == 1)        gSettings.displayMonitor = kSecondary;
  270.     }
  271. }
  272.  
  273.